//	ID : pallab81
// 	PROG : 11407
// 	LANG : C++
// 	2011-08-31-16.57.34 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
const int inf = 10000;
int memo[inf+10];
int N;

inline void go(){
    memo[0]=0;
    foE(i,1,inf){
        int best=(int)1023456789;
        for(int j=1; j*j<=i; ++j ){
            int baki_tuku = i- (j*j);
            best = min(best, memo[baki_tuku]+1);
        }
        memo[i]=best;
        //printf("%d = %d\n",i,memo[i]);wait(.3);
    }
}

inline void Proc(){
    CI(N);
    printf("%d\n",memo[N]);
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif
    go();
    int cases=1;
    for( CI(cases); cases; --cases){
        Proc();
    }


return 0;
}
